package top.kaoshanji.p1ch04a;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * 代码清单test-p1ch04a-02：基于Web服务器的随机端口测试
 * @author kaoshanji
 * ^_^
 * create time 2025/5/16 17:35
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = ReadingListApplication.class)
@WebIntegrationTest(randomPort = true)
public class SimpleWebTest {

    @Value("${local.server.port}")
    private int port;

    @Test
    public void testRestTemplate() {

        TestRestTemplate rest = new TestRestTemplate();
        String s = rest.getForObject("http://localhost:{port}/bogusPage", String.class, port);
        System.out.println(s);

    }

}
